package com.chocho.consumeserver.config;

import com.alibaba.fastjson.JSONObject;
import com.chocho.consumeserver.utils.Msg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

/**
 * Created by chocho on 2022/5/20.
 */
public class ServerEncoder implements Encoder.Text<Msg> {

    private static final Logger log = LoggerFactory.getLogger(ServerEncoder.class);

    @Override
    public String encode(Msg msg) throws EncodeException {
        try {
            return JSONObject.toJSONString(msg);
        }catch (Exception e){
            log.error("",e);
        }
        return null;
    }

    @Override
    public void init(EndpointConfig endpointConfig) {

    }

    @Override
    public void destroy() {

    }
}
